package com.cwt_taxi_xa;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.cwt_taxi_xa.constants.Constants;
import com.cwt_taxi_xa.constants.MyStatus;
import com.cwt_taxi_xa.constants.SPConstants;
import com.cwt_taxi_xa.data.DataUtil;
import com.cwt_taxi_xa.db.bll.LocalInfoBiz;
import com.cwt_taxi_xa.model.LocalInfo;
import com.cwt_taxi_xa.protocol.BusinessProcessSZ;
import com.cwt_taxi_xa.protocol.DeviceBiz;
import com.cwt_taxi_xa.protocol.MCUUtil;
import com.cwt_taxi_xa.protocol.MeterDecoder;
import com.cwt_taxi_xa.protocol.can.ConditioningDecode;
import com.cwt_taxi_xa.protocol.can.IViewAirConditionState;
import com.cwt_taxi_xa.service.FloatService;
import com.cwt_taxi_xa.util.AppBiz;
import com.cwt_taxi_xa.util.AppLog;
import com.cwt_taxi_xa.util.DateUtil;
import com.cwt_taxi_xa.util.GPSUtil;
import com.cwt_taxi_xa.util.SPUtils;
import com.cwt_taxi_xa.util.TTsFunction;
import com.cwt_taxi_xa.util.Tools;
import com.cwt_taxi_xa.util.VersionBiz;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class ActivityMain extends CWTBaseActivity {
	final static String TAG = "ActivityMain";
//	private UDPBuild udpBuild;

	/**
	 * textview对应id
	 * 2-----4----6--------7--------23-----15-------12-----------13-----------14----16------17------18-------21
	 * 方向-时速-日夜运价-运价价格-运营时长-运营时长-当日运营次数-当日累计金额-空车率-司机姓名-公司名-监督电话-从业资格证号
	 * 0     1    2        3         4       5        6           7           8     9       10     11       12
	 */
	int[] tvids = { R.id.textView2, R.id.textView4, R.id.textView6, R.id.textView7, R.id.textView23, R.id.textView15, R.id.textView12, R.id.textView13, R.id.textView14, R.id.textView16, R.id.textView17, R.id.textView18,
			R.id.textView21 };

	/**
	 * imageview对应id 3---------5------11-----12------13----14----15----16----2
	 * 司机照片-空重车-bt导航-bt影音-bt电召-bt订单-btDVR-bt设置-速度 0 1 2 3 4 5 6 7 8
	 */
	int[] ivids = { R.id.imageView3, R.id.imageView5, R.id.imageView11, R.id.imageView12, R.id.imageView13, R.id.imageView14, R.id.imageView15, R.id.imageView16, R.id.imageView2, R.id.imageView6 };

	/**
	 * 导航-------------影音--------------电召-------------订单-------------DVR--------
	 * ------设置
	 */
	int[] rlyids = { R.id.rly_click1, R.id.rly_click2, R.id.rly_click3, R.id.rly_click4, R.id.rly_click5, R.id.rly_click6 , R.id.rly_click_bluetooth };

	int[] btivs1 = { R.drawable.cwtic_mainbt_dh1, R.drawable.cwtic_mainbt_yy1, R.drawable.cwtic_mainbt_dz1, R.drawable.cwtic_mainbt_dd1, R.drawable.cwtic_mainbt_dvr1, R.drawable.cwtic_mainbt_set1 };
	int[] btivs2 = { R.drawable.cwtic_mainbt_dh2, R.drawable.cwtic_mainbt_yy2, R.drawable.cwtic_mainbt_dz2, R.drawable.cwtic_mainbt_dd2, R.drawable.cwtic_mainbt_dvr2, R.drawable.cwtic_mainbt_set2 };

	TextView[] tvs;
	ImageView[] ivs;
	RelativeLayout[] rlys;

	ImageView iv_online, iv_center, iv_gps,ivFuelError;
	TextView tv_time;

	Animation mAlphaAnim ;

	private ImageView ivPtcHeater,ivFuelHeater;
	private LinearLayout llHeaterToggle;

	String dir = "--";
	int direction = -1;
	String time = "--";
	public Handler handler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			if (msg.what == 10001) {// 刷新时间
				time = (String) msg.obj;
				tv_time.setText(time);
				direction = GPSUtil.getInstance().getLocInfo().getDirection();
				if (direction < 22.5) {
					dir = "正北";
				} else if (direction < 67.5) {
					dir = "东北";
				} else if (direction < 112.5) {
					dir = "正东";
				} else if (direction < 157.5) {
					dir = "东南";
				} else if (direction < 202.5) {
					dir = "正南";
				} else if (direction < 247.5) {
					dir = "西南";
				} else if (direction < 292.5) {
					dir = "正西";
				} else if (direction < 337.5) {
					dir = "西北";
				} else {
					dir = "正北";
				}
				tvs[8].setText("速度：" + (GPSUtil.getInstance().getLocInfo().getSpeed()/10) + "km/H     方向：" + dir);
//				showDayCount();
			} else if (msg.what == 10002) {// 单次运营开始
				yyStart(0);
			} else if (msg.what == 10003) {// 单次运营结束
				String result = (String) msg.obj;
				yyEnd(result);
			} else if (msg.what == 10004) {// 刷新运营时长
				if (yyThread) {

					if(System.currentTimeMillis()-yyTime>1000*60*60*24*365){
						//未网络校时翻牌，导致校时后运营时长变态
						String[] ss = tvs[5].getText().toString().split(":");
						int miao = Integer.parseInt(ss[0])*60*60;
						miao+=Integer.parseInt(ss[1])*60;
						miao+=Integer.parseInt(ss[2]);
						miao++;
						yyTime = System.currentTimeMillis()-(miao*1000);
					}

					tvs[5].setText(DateUtil.getShowTime2(yyTime));
				}
				// 检查计价器是否无声切换到空车
				if (!MyStatus.zhongche) {
					yyEnd(null);
				}
			} else if (msg.what == 10005) {
				// 当前主界面，收到计价器未开机心跳，同步状态
				TTsFunction.speakText("同步计价器状态");
				SPUtils.setParam(SPConstants.SPK_signin, false);
				startActivity(new Intent(ActivityMain.this, ActivityWaitQD.class));
				finish();
			}
			else if (msg.what == 10006) {
				// 翻牌后15秒，判断还在运营状态就数人头
				if(yyThread){
					AppLog.d(TAG,"NumberOfPeople 翻牌后15秒，判断还在运营状态就数人头 ");
					Intent intent = new Intent(FloatService.action_camera);
					intent.putExtra("type", 1);
					sendBroadcast(intent);
				}
			}

			else if (msg.what == 10007) {
				showDayCount();
			}

			else if (msg.what == 1007) {
				// 刷新右上角状态位-网络
				iv_online.setImageResource((Boolean) msg.obj ? R.drawable.cwtic_bs1_on : R.drawable.cwtic_bs1_off);
			} else if (msg.what == 1008) {
				// 刷新右上角状态位-平台
				iv_center.setImageResource((Boolean) msg.obj ? R.drawable.cwtic_bs2_on : R.drawable.cwtic_bs2_off);
			} else if (msg.what == 1009) {
				// 刷新右上角状态位-定位
				iv_gps.setImageResource((Boolean) msg.obj ? R.drawable.cwtic_bs3_on : R.drawable.cwtic_bs3_off);
			}

		};
	};

	int lsyccl = 0;

	int gpsindex = 0;//测试。。。。。。。

	TextView tv_youxiaoqi;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.openSwipeBack(false);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_aa_main);


		initView();





		//测试-----------------------
//		final byte[] gpsbugger = new byte[1024];
//		 udpBuild = UDPBuild.getUdpBuild();
//	        udpBuild.setUdpReceiveCallback(new UDPBuild.OnUDPReceiveCallbackBlock() {
//	            @Override
//	            public void OnParserComplete(DatagramPacket data) {
//
//	            	for (int i = 0; i < data.getData().length; i++) {
//	            		if(data.getData()[i]==0x24){
//	            			gpsbugger[0] = data.getData()[i];
//	            			gpsindex = 1;
//	            		}else if(data.getData()[i]==0x0A){
//	            			gpsbugger[gpsindex] = data.getData()[i];
//	            			gpsindex++;
//	            			SerialPortService.getInstance().sendSerialData5(Tools.byteTobyte(gpsbugger, 0, gpsindex));
////	            			AppLog.e(new String(Tools.byteTobyte(gpsbugger, 0, gpsindex)));
//	            			gpsindex = 0;
//	            		}else{
//	            			gpsbugger[gpsindex] = data.getData()[i];
//	            			gpsindex++;
//	            		}
//					}
//
//
////	                String strReceive = new String(data.getData(), 0, data.getLength());
////	                SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
////	                Date curDate =  new Date(System.currentTimeMillis());
////	                String str = formatter.format(curDate);
//////	                TextView receive = findViewById(R.id.receive_textView);
//////	                receive.append(str + ':' + strReceive + '\n');
////
////	                if (strReceive.contains("GetStatusGpsOrigin"))
////	                    Log.e("MainActivity", "接收数据：" + strReceive);
//	            }
//	        });






		/**
		 * 临时报警测试
		 */
		final ImageView iv6 = (ImageView) findViewById(R.id.imageView6);
		iv6.setTag(false);
		iv6.setOnLongClickListener(new OnLongClickListener() {

			@Override
			public boolean onLongClick(View arg0) {
				// TODO Auto-generated method stub
				//SerialPortService.getInstance().sendSerialData6(MeterEncoder.getMeterDtuBody("00E3",Tools.parseHexStr2Byte("90")));
				MeterDecoder.processMeter("00E3", Tools.parseHexStr2Byte("90"), ActivityMain.this);

				//MCUUtil.mVoiceTool.start();
				return true;
			}
		});
		MCUUtil.mVoiceTool.start();
		BusinessProcessSZ.photographTask.init();
		MCUUtil.mConditioningDecode.registerState(conditionState);
		iv6.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				TTsFunction.speakText("2222222222222222");
//				startActivity(new Intent(ActivityMain.this, ActivityCardInfo.class));
				//VoiceEncode.encode(3,5,new byte[]{0x01});
//				TimerCommon.count_vUp = 20*60;

//				DecoderSZ55aa.decoderData("test",
//						Tools.parseHexStr2Byte(" 55 AA \j0 38 02 02 00 E1 36 31 30 35 32 31 31 39 38 32 31 30 32 37 34 32 36 31 30 35 32 31 31 39 38 32 31 30 32 37 34 32 37 58 00 41 33 4E 39 31 4C 20 19 05 19 17 02 00 00 AB 7E 90 BB 55 AA ")
//						, ActivityMain.this);


				//测试wifi引脚复位
//				new Thread(new Runnable() {
//					@OverridejhrfgujiasdfghjklgfdsaGYTREW3ERTYU8[]\782+
//					public void run() {
//						try {
//							GPIOUtil.writeToDevice(0, "/proc/input5");
//							AppLog.e("wifi引脚状态："+GPIOUtil.readIOState("/proc/input5"));
//							Thread.sleep(1000);
//							GPIOUtil.writeToDevice(1, "/proc/input5");
//							AppLog.e("wifi引脚状态："+GPIOUtil.readIOState("/proc/input5"));
//							Thread.sleep(1000);
//							GPIOUtil.writeToDevice(0, "/proc/input5");
//							AppLog.e("wifi引脚状态："+GPIOUtil.readIOState("/proc/input5"));
//							Thread.sleep(1000);
//							GPIOUtil.writeToDevice(1, "/proc/input5");
//							AppLog.e("wifi引脚状态："+GPIOUtil.readIOState("/proc/input5"));
//						} catch (Exception e) {
//						}
//					}
//				}).start();


//				WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
//				if (wifiManager.isWifiEnabled()) {
//					wifiManager.setWifiEnabled(false);
//				} else {
//					wifiManager.setWifiEnabled(true);
//				}


//				TimerCommon.count_vUp = 20*60;

//				saveTodayyy(85);

				//高德调用示例
//				Intent intent = new Intent();
//				intent.setAction("AUTONAVI_STANDARD_BROADCAST_RECV");
//				intent.putExtra("KEY_TYPE", 10032);
//				intent.putExtra("EXTRA_SNAME", "百翔软件园酒店");
//				intent.putExtra("EXTRA_SLON", 118.182682);
//				intent.putExtra("EXTRA_SLAT",24.496706);
//				intent.putExtra("EXTRA_FMIDNAME","蔡塘");
//				intent.putExtra("EXTRA_FMIDLON",118.162947);
//				intent.putExtra("EXTRA_FMIDLAT",24.492793);
//				intent.putExtra("EXTRA_SMIDNAME","太川大楼");
//				intent.putExtra("EXTRA_SMIDLON",118.148825);
//				intent.putExtra("EXTRA_SMIDLAT",24.483256);
//				intent.putExtra("EXTRA_TMIDNAME","世界山庄");
//				intent.putExtra("EXTRA_TMIDLON",118.163917);
//				intent.putExtra("EXTRA_TMIDLAT",24.47658);
//				intent.putExtra("EXTRA_DNAME","椰风寨");
//				intent.putExtra("EXTRA_DLON",118.17581);
//				intent.putExtra("EXTRA_DLAT",24.453688);
//				intent.putExtra("EXTRA_DEV",0);
//				intent.putExtra("EXTRA_M",0);
//				sendBroadcast(intent);

//				Intent intent = new Intent( "com.yh.car.nav.YJDH");
//				intent.putExtra("slongitude", 118.182682);//double
//				intent.putExtra("slatitude", 24.496706);
//				intent.putExtra("elongitude", 118.17581);
//				intent.putExtra("elatitude", 24.453688);
//			sendBroadcast(intent);

				//测试获取其它qpp包名
//				AppBiz ab = new AppBiz(MainApplication.topActivity);
//				List<AppInfo> apps = ab.queryFilterAppInfo(AppBiz.FILTER_THIRD_APP);
//				for (int i = 0; i < apps.size(); i++) {
//					AppLog.e("12345------------"+apps.get(i).getPkgName());
//				}
//
//				//com.nd.assistance
//				execCommand("pm","uninstall", "com.nd.assistance");
//
//				apps = ab.queryFilterAppInfo(AppBiz.FILTER_THIRD_APP);
//				for (int i = 0; i < apps.size(); i++) {
//					AppLog.e("12345------------"+apps.get(i).getPkgName());
//				}


//				TimerCommon.count_vUp = 60*20;


//				boolean baojin = (Boolean) iv6.getTag();

				//测试shell指令
//				AppLog.e(ShellUtils.checkRootPermission()+"");

				//测试实时音频数据录音
//				if(AudioUtil.getInstance().isRecording){
//					AudioUtil.getInstance().stopRecord();
//				}else{
//					AudioUtil.getInstance().startRecord();
//				}


				//测试905标准tsm刷卡模块
//				startActivity(new Intent(ActivityMain.this, ActivityTsm905.class));

				//测试905标准tsm刷卡模块
//				SerialPortService.getInstance().sendSerialData2(Tools.parseHexStr2Byte("55 AA 00 0B 03 00 00 00 20 19 03 01 14 47 46 26 55 AA "));
//

				//测试升级系统
//				public boolean checkPackage(String packageName) {
//			        if (packageName == null || "".equals(packageName))
//			            return false;
//			        try {
//			            ApplicationInfo info = getPackageManager().getApplicationInfo(
//			                    packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
//			            return true;
//			        } catch (NameNotFoundException e) {
//			            return false;
//			        }
//			    }
//
//				private void startLocalRecovery(){
//					if(checkPackage("com.softwinner.settingsassist")&&checkPackage("com.softwinner.TvdFileManager")){
//						Log.d(TAG,"apk exist!");
//						Intent intent = new Intent("softwinner.intent.action.RECOVREY");
//						startActivity(intent);
//					}else{
//					    //显示Toast
//						UToast.makeUText( this , getString( R.string.not_support_local_update ) , UToast.LENGTH_SHORT ).show( );
//
//					}
//				}
//			        try {
//			            ApplicationInfo info = getPackageManager().getApplicationInfo(
//			            		"com.softwinner.TvdFileManager",
////			            		"com.softwinner.settingsassist",
//			            		PackageManager.GET_UNINSTALLED_PACKAGES);
//			            AppLog.e("1");
//			        } catch (NameNotFoundException e) {
//			            AppLog.e("2");
//			        }
//				Intent intent = new Intent("softwinner.intent.action.RECOVREY");
//				startActivity(intent);



//				Intent intent =  new Intent(Settings.ACTION_WIFI_SETTINGS);
//                startActivity(intent);


				//测试下载
				//https://mapdownload.autonavi.com/amapauto/apk/autobasic/guanwangV4.0.0.6108_TATE533299P.apk?u=ebb84419d422e38bcd29bd888f01741c
//				new Thread(new Runnable() {
//
//					@Override
//					public void run() {
//						// TODO Auto-generated method stub
//						Request request = new Request.Builder().url("https://mapdownload.autonavi.com/amapauto/apk/autobasic/guanwangV4.0.0.6108_TATE533299P.apk?u=ebb84419d422e38bcd29bd888f01741c").build();
//						new OkHttpClient().newCall(request).enqueue(new Callback() {
//							@Override
//							public void onFailure(Call call, IOException e) {
//								// 下载失败
//								e.printStackTrace();
//								Log.i("DOWNLOAD", "download failed");
//							}
//
//							@Override
//							public void onResponse(Call call, Response response) throws IOException {
//								try {
//									//这种莫名其妙的文件地址，获取不到总大小，只好用大概值代替
//									AppLog.e("总大小："+response.body().contentLength() );
//									InputStream is = response.body().byteStream();// 从服务器得到输入流对象
//									BufferedInputStream bis = new BufferedInputStream(is);
//
//									File file = new File(Environment.getExternalStorageDirectory(), "高德.apk");
//									FileOutputStream fos = new FileOutputStream(file);
//
//									byte[] buffer = new byte[1024];
//									int len;
//									int total = 0;
//
//									boolean downok = true;
//									while ((len = bis.read(buffer)) != -1) {
//											fos.write(buffer, 0, len);
//											total += len;
//											AppLog.e(total);
//									}
//									if(downok){
//										fos.flush();
//										fos.close();
//										bis.close();
//										is.close();
//									}
//
//								} catch (Exception e) {
//									e.printStackTrace();
//								}
//
//							}
//
//						});
//					}
//				}).start();



				//测试郑工gps广播透传
//				String msg = "#__#sim=,function=CDvrSdk.GetStatusGpsOrigin,seq=30,in=0,out=0$cr$";
//		        String hex = HexConvert.convertStringToHex(msg);
//		        byte[] bytes = HexConvert.hexStringToBytes(hex);
//		        byte[] tail = new byte[]{0x0a, 0x00};
//
//		        final ByteBuffer buffer = ByteBuffer.allocate(bytes.length + tail.length);
//		        buffer.put(bytes);
//		        buffer.put(tail);
//
//		        Log.e("MainActivity", "sendMessage: " + HexConvert.BinaryToHexString(buffer.array()));
//
//				new Thread(new Runnable() {
//
//					@Override
//					public void run() {
//						// TODO Auto-generated method stub
//						try {
//							for (int i = 0; i < 6000; i++) {
//								Thread.sleep(1000);
//								udpBuild.sendMessage(buffer.array());
//							}
//						} catch (Exception e) {
//							// TODO: handle exception
//						}
//					}
//				}).start();


				//测试计价器数据出错
//				DecoderSZ55aa.decoderData("计价器", Tools.parseHexStr2Byte("" +
//						"55 AA 00 71 02 02 00 E8 41 41 33 33 33 33 31 32 33 34 " +
//						"35 00 00 00 00 00 00 00 00 00 00 00 31 32 33 34 35 00 " +
//						"00 00 00 00 00 00 00 00 00 00 00 00 00 19 01 22 11 01 " +
//						"11 01 00 00 00 00 00 00 00 00 00 00 00 00 85 00 00 00 " +
//						"38 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 " +
//						"00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 " +
//						"00 00 00 00 00 00 00 00 00 1E 55 AA" +
//						""), ActivityMain.this);





				//测试ftp
//				new Thread(new Runnable() {
//
//					@Override
//					public void run() {
//						// TODO Auto-generated method stub
//						VersionBiz.doCheckFTP();
//					}
//				}).start();

				//换屏更换设备号
//				new Thread(new Runnable() {
//					@Override
//					public void run() {
//						ChangeNumInfo info = new ChangeNumInfo();
//						info.setTermNum1("");
//						info.setTermNum2("");
//						Gson g = new Gson();
//						String result = TimerCommon.doJsonPost("http://taxi.jpfwpt.com:4657/rest/changeMac", g.toJson(info));
//						AppLog.e("-------------");
//						AppLog.e(result);
//						AppLog.e("-------------");
//					}
//				}).start();

//				SerialPortService.getInstance().sendSerialData6(MeterEncoder.queryMeterState());

//				Log.e("MeterBusinessProcess", "发送司机信息关机");
//				SerialPortService.getInstance().sendSerialData6(MeterEncoder.sendDriverInfoForPower905("00E3",
//						"",
//						"",
////						DataUtil.getCompanyCode(),
////						DataUtil.getDriverCode(),
//						SPUtils.getParamString(SPConstants.SPK_carcode, SPConstants.SPV_carcode),
//						DateUtil.getNowDateToMeter(), 1, "0000000000",
//						"0000", "90"));


//				getMacAddress();

				//读mcu版本
//				MCUUtil.checkV();
//				MCUUtil.UpV2();

				//测试郑工dvr参数查询设置
//				DvrService.getInstance().sendHttpGetSet();


//				DvrService.getInstance().sendSet("1234567890", "112365");

				//测试青岛恒星数据
//				NianBaoUtil.nbjjq(Tools.parseHexStr2Byte("55AA0098020100E83F4154303031313200000000000000000000000000003133000000000000000000000000000000000018112220012005000000000000000000030001000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004655AA"), ActivityMain.this);

//				VersionBiz versionBiz = new VersionBiz(ActivityMain.this);
//				versionBiz.doCheckSJInfor("12345678");

				//测试平台立即拍照指令
//				Intent intent = new Intent(FloatService.action_camera);
//				intent.putExtra("type", 2);
//				intent.putExtra("seq", 0);
//				intent.putExtra("w", 640);
//				intent.putExtra("h", 480);
//				intent.putExtra("channelId", 2);
//				MainApplication.topActivity.sendBroadcast(intent);


//				DvrService.getInstance().sendPICOrder(1);

//				DvrService.getInstance().chonglianceshi();


				//测试异常
//				int iii = Integer.parseInt("4few3");



//				 SerialPortService.getInstance().sendSerialData1(Tools.parseHexStr2Byte("55 AA 00 0B 03 00 00 00 20 18 11 14 20 16 42 41 55 AA "));
//				 SerialPortService.getInstance().sendSerialData1(Tools.parseHexStr2Byte("010203010203010203010203010203010203010203010203"));
//				 SerialPortService.getInstance().sendSerialData7(Tools.parseHexStr2Byte("55F500050102038AFF55"));
//				MCUUtil.touchuan(Tools.parseHexStr2Byte("10 10 10"));
//				MCUUtil.touchuan(5, Tools.parseHexStr2Byte("55 AA 00 0B 03 00 00 00 20 18 11 14 20 16 42 41 55 AA "));

				// if(baojin){
				// iv6.setTag(false);
				// SerialPortService
				// .getInstance()
				// .sendSerialData1(
				// DDUtil.getDDstatue(7));
				// }else{
				//
				// iv6.setTag(true);
				// SerialPortService
				// .getInstance()
				// .sendSerialData1(
				// DDUtil.getDDstatue(6));
				// }

				// 测试设置指令
				// SZDecoder.decoderQH808Data(Tools.parseHexStr2Byte("7E8103005B1038241231680071001006636D6E657431001105474E53533100130B3231382E352E38302E3234001205474E535332001804000022BC001406636D6E657432001505474E53533300170A3231382E352E38302E36001605474E535334001904000022BDD97E"),
				// ActivityMain.this);
				// Decoder.decoderQH808Data(Tools.parseHexStr2Byte("7E8103007710382412316800B900200400000000002104000000000022040000002D00230400000028002404000000190025040000001E00260400000014002704000000230028040000000A002904000007D0002A04000005DC002B0400000258002C04000003E8002D04000001F4002E0400000320002F04000000C80030040000002D8C7E"),
				// ActivityMain.this);
				// 测试位置追踪
				// SZDecoder.decoderQH808Data(Tools.parseHexStr2Byte("7E82020007103824123168002700000F00000078907E"),
				// ActivityMain.this);

				// startActivity(new Intent(ActivityMain.this,
				// ActivityWriteCard.class));

				// 模拟刷卡签退 卡类型-企业号-司机号-车牌
				// String[] info = {"1","12345","12345","12345"};
				// Intent intent = new Intent(MainApplication.topActivity,
				// ActivityQT.class);
				// intent.putExtra("type", 2);
				// intent.putExtra("info", info);
				// MainApplication.topActivity.startActivity(intent);

				// 0x7a 0x31 00 03 01 xor 7a
				// String testbyte = "55 31 00 03 01";
				// SerialPortService.getInstance().sendSerialData7(getMCUData(Tools.parseHexStr2Byte(testbyte)));

				// startActivity(new Intent(ActivityMain.this,
				// ActivityWriteCard.class));

				// try {
				// // /mnt/usbhost/Storage01
				// File f = new File("/mnt/usbhost/Storage01", "usbtest.txt");
				// FileOutputStream fos = new FileOutputStream(f);
				// fos.write("asdfasdfasdf".getBytes());
				// fos.flush();
				// fos.close();
				// } catch (Exception e) {
				// // TODO: handle exception
				// e.printStackTrace();
				// }

				// 重启
				// Toast.makeText(ActivityMain.this, "重启", 2000).show();
				// try {
				// Intent intent = new
				// Intent("android.intent.action.ACTION_REQUEST_SHUTDOWN");
				// intent.putExtra("android.intent.extra.KEY_CONFIRM", true);
				// //其中false换成true,会弹出是否关机的确认窗口
				// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				// startActivity(intent);
				//
				// } catch (Exception ex) {
				// ex.printStackTrace();
				// }

			}

		});

		// 临时异常处理
//		tvs[9].setOnClickListener(new OnClickListener() {
//
//			@Override
//			public void onClick(View arg0) {
//				// TODO Auto-generated method stub
//				if (lsyccl > 5) {
//					SPUtils.setParam(SPConstants.SPK_signin, false);
//					TTsFunction.speakText("异常处理，强制设置为签退状态");
//					lsyccl = 0;
//				} else {
//					lsyccl++;
//				}
//			}
//		});
	}











	void initView() {
		tv_time = (TextView) findViewById(R.id.textView1);
		iv_online = (ImageView) findViewById(R.id.imageView8);
		iv_center = (ImageView) findViewById(R.id.imageView9);
		iv_gps = (ImageView) findViewById(R.id.imageView10);
		ivFuelError = (ImageView) findViewById(R.id.iv_fuel_error);

		ivPtcHeater = (ImageView) findViewById(R.id.iv_ptc_heater);
		ivFuelHeater = (ImageView) findViewById(R.id.iv_fuel_heater);
		llHeaterToggle = (LinearLayout)findViewById(R.id.ll_heater_toggle);

		ivPtcHeater.setOnClickListener(onClickListener);
		ivFuelHeater.setOnClickListener(onClickListener);


		tv_youxiaoqi = (TextView) findViewById(R.id.textView2018);

		tvs = new TextView[tvids.length];
		ivs = new ImageView[ivids.length];
		rlys = new RelativeLayout[rlyids.length];
		for (int i = 0; i < tvids.length; i++) {
			tvs[i] = (TextView) findViewById(tvids[i]);
		}
		for (int i = 0; i < ivids.length; i++) {
			ivs[i] = (ImageView) findViewById(ivids[i]);
		}
		for (int i = 0; i < rlyids.length; i++) {
			rlys[i] = (RelativeLayout) findViewById(rlyids[i]);
			rlys[i].setTag(i);
			rlys[i].setOnClickListener(onClick);
		}

		// 测试读写卡------------------------------------
//		ivs[0].setOnClickListener(new OnClickListener() {
//			@Override
//			public void onClick(View arg0) {
//				startActivity(new Intent(ActivityMain.this, ActivityWriteCard.class));
//			}
//		});



		findViewById(R.id.layout_meter).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				startActivity(new Intent(ActivityMain.this, BusinessCount.class));
			}
		});

		mAlphaAnim = AnimationUtils.loadAnimation(this, R.anim.alpha_anim);
	}

	/**
	 * textview对应id
	 * 2-----4----6--------7--------23-----15-------12-----------13--
	 * ---------14----16------17------18-------21
	 * 方向-时速-日夜运价-运价价格-运营时长-运营时长-当日运营次数-当日累计金额-空车率-司机姓名-公司名-监督电话-从业资格证号 0 1 2 3
	 * 4 5 6 7 8 9 10 11 12 imageview对应id
	 * 3---------5------11-----12------13----14----15----16----2
	 * 司机照片-空重车-bt导航-bt影音-bt电召-bt订单-btDVR-bt设置-速度 0 1 2 3 4 5 6 7 8
	 * 导航------------
	 * -影音--------------电召-------------订单-------------DVR--------------设置
	 */
	public static boolean yyThread = false;
	public static long yyTime;

	void yyStart(long time) {
		if(time==0){
			handler.sendEmptyMessageDelayed(10006, 10*1000);
		}
		if(time==0){
			yyTime = new Date().getTime();
		}
		ivs[8].setImageResource(R.drawable.cwtic_main_sudu2);
		ivs[1].setImageResource(R.drawable.cwtic_main_zaike);
		tvs[4].setBackgroundResource(R.drawable.cwt_yuanjiao_2);
		tvs[5].setTextColor(Color.parseColor("#ffffff"));
		for (int i = 0; i < 6; i++) {
			ivs[i + 2].setImageResource(btivs2[i]);
		}
		yyThread = true;
		new Thread(new Runnable() {
			@Override
			public void run() {
				while (yyThread) {
					try {
						Thread.sleep(1000);
						handler.sendMessage(handler.obtainMessage(10004));
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}).start();
	}

	@SuppressLint("ResourceAsColor")
	void yyEnd(String result) {
		yyThread = false;
		ivs[8].setImageResource(R.drawable.cwtic_main_sudu1);
		ivs[1].setImageResource(R.drawable.cwtic_main_kongche);
		tvs[4].setBackgroundResource(R.drawable.cwt_yuanjiao_1);
		tvs[5].setTextColor(Color.parseColor("#90ffffff"));
		tvs[5].setText("00:00:00");
		for (int i = 0; i < 6; i++) {
			ivs[i + 2].setImageResource(btivs1[i]);
		}
		if (result != null) {
			Intent intent = new Intent(ActivityMain.this, ActivityPJ.class);
			intent.putExtra("result", result);
			intent.putExtra("yytime", DateUtil.getShowTime2(yyTime));
			startActivity(intent);
		}

//		DDUtil.sendText2TT(1);
	}



	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();


		tvs[12].setText(hideId(DataUtil.getDriverCode()));
		//tvs[12].setText(hideId("610104197310253457"));

		handler.sendEmptyMessageDelayed(10007, 1000);

//		tvs[10].setText("所属公司：贵州吉德士\n车牌号码：" + DeviceBiz.getCarNumber() + "\n发证机关：贵阳市道路运输管理局");
//		tvs[10].setText("所属公司：西汽一公司\n车牌号码：" + DeviceBiz.getCarNumber() + "\n发证机关：西安市出租车管理处");


		Bitmap bitmap = null;

		if(Constants.sijiinfo==null||Constants.sijiinfo.getName()==null||Constants.sijiinfo.getName().length()<1){
			Constants.sijiinfo=VersionBiz.getSijiInfo(DataUtil.getlastCarNum());
		}


		if(Constants.sijiinfo!=null){
			tvs[9].setText(Constants.sijiinfo.getName());
			tv_youxiaoqi.setText("有效期： "+Constants.sijiinfo.getCertificateData());
			tvs[10].setText("所属公司："+Constants.sijiinfo.getCompanyname()+"\n车牌号码：" + DeviceBiz.getCarNumber() + "\n发证机关：西安市出租车管理处");
			tvs[11].setText(Constants.sijiinfo.getMobile());
			bitmap = ActivityCamera.getLoacalBitmap(Constants.sijiinfo.getPhoto());
		}else{
			tvs[9].setText("");
//			tv_youxiaoqi.setText("有效期： "+Constants.sijiinfo.getCertificateData());
			tvs[10].setText("所属公司：\n车牌号码：" + DeviceBiz.getCarNumber() + "\n发证机关：西安市出租车管理处");
//			bitmap = ActivityCamera.getLoacalBitmap(Constants.SDPath+"司机照片.jpg");
		}

		if(bitmap!=null){
			ivs[9].setImageBitmap(bitmap);
		}

		if(MyStatus.zhongche){
			yyStart(yyTime);
		}

		//测试数人头
//		new Thread(new Runnable() {
//
//			@Override
//			public void run() {
//				try {
//					File f = new File("/mnt/sdcard/");
//					String[] ss = f.list();
//					for (int i = 0; i < ss.length; i++) {
//						if(ss[i].endsWith("png")){
//							AppLog.e(ss[i]);
//							byte[] data = FileUtil.readFileByBytes("/mnt/sdcard/"+ss[i]);
//							AppLog.e(ss[i]+"\n"+FaceMatch.detect(data));
//						}
//					}
////			FileUtil.readFileByBytes("/mnt/sdcard/test2.jpg");
//
//				} catch (Exception e) {
//					// TODO: handle exception
//				}
//			}
//		}).start();

		if(!checkInstall("com.didachuxing.taxi.terminaldevice")){
			MCUUtil.Insdida(ActivityMain.this);
		}

	}

	private LocalInfoBiz localInfoBiz;

	/**
	 * 初始化数据
	 */
	ArrayList<LocalInfo> infosToday;
	double amount;
	LocalInfo info;
	String data;
	byte[] dataByte;
	int amountIndex;
	BigDecimal decimal;
	double subAmount;
	public void showDayCount() {
//		if (localInfoBiz == null) {
//			localInfoBiz = LocalInfoBiz.getInstance();
//		}
//		// 当日汇总
//		infosToday = localInfoBiz.getTodayBusinessInfos();
//		if (infosToday != null && infosToday.size() != 0) {
//			tvs[6].setText("" + infosToday.size());
//
//			amount = 0;
//			for (int i = 0; i < infosToday.size(); i++) {
//				info = infosToday.get(i);
//				data = info.getData();
//				dataByte = Tools.yxReversal(Tools.parseHexStr2Byte(data));
//				amountIndex = 13 + 25 + 25 + 15 + 58;
//
//				decimal = new BigDecimal(Tools.bcd2Str(Tools.byteTobyte(dataByte, amountIndex, 3)));
//				decimal = decimal.divide(new BigDecimal(10));
//				subAmount = decimal.doubleValue();
//				amount += subAmount;
//			}
//
//			tvs[7].setText(DecimalUtil.priceFormat(amount));
//		} else {
//			tvs[6].setText("0");
//			tvs[7].setText("0");
//		}
		tvs[6].setText(String.valueOf(gettodaycount()));
		tvs[7].setText(gettodayyystr());
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
	}




	public static void changeTopLightStatus(int ddStatus) {
		// TODO Auto-generated method stub
		// empty.setBackgroundResource(R.drawable.call);
		// shutdown.setBackgroundResource(R.drawable.shutdown);
		// shunt.setBackgroundResource(R.drawable.handover);
		/**
		 * 顶灯状态 0x00:空车 前顶灯显示（常亮） 0x01:重车 前顶灯显示（可选） 0x02:停运 前顶灯显示（间隔3秒闪烁）
		 * 0x03:电召 前顶灯显示（间隔3秒闪烁） 0x04:报警 前顶灯显示“报警”（间隔3秒闪烁）后顶灯显示“报警求助” 0x05:防伪密标
		 * 即稽查，保留，不实现，采用3.7 3.8实现 0x06:交班 前顶灯显示（常亮） 0xFF：取消 取消终端设置的营运状态，改由控制开关控制
		 */
		switch (ddStatus) {
			case 3: // 显示“电召”
				// empty.setBackgroundResource(R.drawable.selempty);
				break;
			case 2: // 显示“停运”
				// shutdown.setBackgroundResource(R.drawable.selstop);
				break;
			case 6: // 显示“交班”
				// shunt.setBackgroundResource(R.drawable.selshunt);
				break;
		}
	}

	@Override
	public void setStatus(int index, boolean status) {
		// TODO Auto-generated method stub
		switch (index) {
			case 1:
				handler.sendMessage(handler.obtainMessage(1007, status));
				break;
			case 2:
				handler.sendMessage(handler.obtainMessage(1008, status));
				break;
			case 3:
				handler.sendMessage(handler.obtainMessage(1009, status));
				break;
			default:
				break;
		}
	}

	@Override
	public void sendMsg(int type, Object obj) {
		// TODO Auto-generated method stub
		if (type == 1002) {
			handler.sendMessage(handler.obtainMessage(10001, obj));
		}
		if (type == 1008) {
			handler.sendMessage(handler.obtainMessage(10002, obj));
		}
		if (type == 1010) {
			handler.sendMessage(handler.obtainMessage(10003, obj));
		}
		if (type == 1011) {
			if (!(Boolean) obj) {
				handler.sendMessage(handler.obtainMessage(10005));
			}
		}
	}

	OnClickListener onClick = new OnClickListener() {

		@Override
		public void onClick(View arg0) {
			int tag = (Integer) arg0.getTag();
			switch (tag) {
				case 0:
					new AppBiz(ActivityMain.this).launchApp("com.autonavi.amapauto");
//				new AppBiz(ActivityMain.this).launchApp("com.autonavi.amapautolite");
					break;
				case 1:
//				new AppBiz(ActivityMain.this).launchApp("com.yho.video");
					if(checkInstall("com.android.music")){
						new AppBiz(ActivityMain.this).launchApp("com.android.music");
					}else{
						MCUUtil.InsMusic(ActivityMain.this);
					}
//				new AppBiz(ActivityMain.this).launchApp("com.supersimpleapps.videoplayer");
//				new AppBiz(ActivityMain.this).launchApp("com.softwinner.TvdVideo");
//				new AppBiz(ActivityMain.this).launchApp("com.mxtech.videoplayer.ad");
					break;
				case 2:
					startActivity(new Intent(ActivityMain.this, MessageFunctionActivity.class));
					// Toast.makeText(ActivityMain.this, "设置为未签到", 1500).show();
					// SPutil.defaultPref().edit().putBoolean("SIGNIN",
					// false).commit();
					break;
				case 3:
					startActivity(new Intent(ActivityMain.this, ActivityFM.class));
					// new
					// AppBiz(ActivityMain.this).launchApp("com.itings.myradio");
					// Toast.makeText(ActivityMain.this, "功能未开发", 1500).show();
					// Toast.makeText(ActivityMain.this, "设置为已签到", 1500).show();
					// SPutil.defaultPref().edit().putBoolean("SIGNIN",
					// true).commit();
					break;
				case 4:
					startActivity(new Intent(ActivityMain.this, VideoActivity.class));
					break;
				case 5:
					// Toast.makeText(ActivityMain.this, "功能未开发", 1500).show();
					// Activity top = CarCallApplication.getInstance().topActivity;
					// Intent intent = new Intent(top, ActivityPJ.class);
					// intent.putExtra("type", 1001);
					// top.startActivity(intent);
					// new
					// AppBiz(ActivityMain.this).launchApp("com.android.settings");
					startActivity(new Intent(ActivityMain.this, FunctionActivity.class));
					break;
				case 6:
					// Toast.makeText(ActivityMain.this, "功能未开发", 1500).show();
					if(checkInstall("com.blink.blinkdemo")){
						new AppBiz(ActivityMain.this).launchApp("com.blink.blinkdemo");
					}else{
						Toast.makeText(ActivityMain.this, "应用未开安装", Toast.LENGTH_SHORT).show();
					}
					break;
			}
		}
	};

	//https://blog.csdn.net/Vermouth_alone/article/details/80273255
	public static String hideId(String id){
		StringBuilder stringBuilder = new StringBuilder(id);
		if(!TextUtils.isEmpty(id)){
			if( id.length() >= 15){
				stringBuilder.replace(10, 14, "****");
				return stringBuilder.toString();
			}
			//屏蔽中间4位
//			int index = id.length()/2;
//			if((index -2 >0) && (index + 2 < id.length())){
//				stringBuilder.replace(index -2, index+ 2, "****");
//			}

		}
		return stringBuilder.toString();
	}


	/**
	 * 检查apk是否安装
	 * @param pkgName
	 * @return
	 */
	public boolean checkInstall(String pkgName) {
		// TODO Auto-generated method stub
		boolean install=false;
		try {
			PackageInfo info = getPackageManager().getPackageInfo(pkgName,1);
			if (info!=null&&info.activities.length>0) {
				install=true;
			}
		} catch (NameNotFoundException e) {
			// TODO Auto-generated catch block
//			e.printStackTrace();
//			AppLog.e(ExceptionUtil.getInfo(e));
		}
		AppLog.i( "包名: "+pkgName+"; 是否安装: " + install);
		return install;
	}

	public static String[] bmd = {"com.autonavi.amapauto",
//					"com.yho.video",
			"com.yho.ym7001a",
			"com.blink.blinkdemo",
			"com.iflytek.speechcloud",
			"com.cwt_taxi_xa",
			"com.android.music",
			"com.didachuxing.taxi.terminaldevice"
	};

	public static String execCommand(String... command) {
		Process process = null;
		InputStream errIs = null;
		InputStream inIs = null;
		String result = "";
		try {
			process = new ProcessBuilder().command(command).start();
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			int read = -1;
			errIs = process.getErrorStream();
			while ((read = errIs.read()) != -1) {
				baos.write(read);
			}
			inIs = process.getInputStream();
			while ((read = inIs.read()) != -1) {
				baos.write(read);
			}
			result = new String(baos.toByteArray());
			if (inIs != null)
				inIs.close();
			if (errIs != null)
				errIs.close();
			process.destroy();
		} catch (IOException e) {

			result = e.getMessage();
		}
		return result;
	}


	public static int todaycount = -1;
	public static int todayyy = -1;
	public static long lastsaveyytime = -1;
	public static String todayyystr = "";
	public static SimpleDateFormat sdf_yy = new SimpleDateFormat("dd");
	public static void saveTodayyy(int yy){
		yyspget();
		if(sdf_yy.format(new Date(lastsaveyytime)).equals(sdf_yy.format(new Date()))){
			todaycount++;
			todayyy+=yy;
		}else{
			todaycount = 1;
			todayyy = yy;
		}
		lastsaveyytime = System.currentTimeMillis();
		yyspset();
	}

	public static int gettodaycount(){
		yyspget();
		return todaycount;
	}

	public static String gettodayyystr(){
		yyspget();
		if(todayyy>9){
			todayyystr = (todayyy/10)+"."+(todayyy%10);
		}else{
			todayyystr = "0."+todayyy;
		}
		return todayyystr;
	}

	public static void yyspset(){
		SPUtils.setParam("todaycount", todaycount);
		SPUtils.setParam("todayyy", todayyy);
		SPUtils.setParam("lastsaveyytime", lastsaveyytime);
	}
	public static void yyspget(){
		if(todayyy==-1||todaycount==-1||lastsaveyytime==-1){
			todaycount = SPUtils.getParamInteger("todaycount", 0);
			todayyy = SPUtils.getParamInteger("todayyy", 0);
			lastsaveyytime = SPUtils.getParamLong("lastsaveyytime", System.currentTimeMillis());
		}
	}

	IViewAirConditionState conditionState = new IViewAirConditionState(){

		@Override
		public void power(int type) {

		}

		@Override
		public void fuelAlarm(int alarm) {
			if(alarm == 1){
				ivFuelError.setVisibility(View.VISIBLE);
				startAnimation();
			}else{
				ivFuelError.setVisibility(View.INVISIBLE);
				stopAnimation();
			}
		}

		@Override
		public void heaterType(int heaterType) {
			//空调加热模式标志位
			if(heaterType == 3){//PTC+燃油加热器
				ivPtcHeater.setVisibility(View.VISIBLE);
				ivFuelHeater.setVisibility(View.VISIBLE);
				llHeaterToggle.setVisibility(View.VISIBLE);
				llHeaterToggle.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
			}else if(heaterType == 2){//燃油加热器
				ivPtcHeater.setVisibility(View.GONE);
				ivFuelHeater.setVisibility(View.VISIBLE);
				llHeaterToggle.setVisibility(View.VISIBLE);
				llHeaterToggle.setShowDividers(LinearLayout.SHOW_DIVIDER_NONE);
			}else if(heaterType == 1){//PTC 加热
				ivFuelHeater.setVisibility(View.GONE);
				ivPtcHeater.setVisibility(View.VISIBLE);
				llHeaterToggle.setVisibility(View.VISIBLE);
				llHeaterToggle.setShowDividers(LinearLayout.SHOW_DIVIDER_NONE);
			}else if(heaterType == 0){
				ivPtcHeater.setVisibility(View.GONE);
				ivFuelHeater.setVisibility(View.GONE);
				llHeaterToggle.setVisibility(View.GONE);
			}else if(heaterType >= 4){
				ivPtcHeater.setVisibility(View.GONE);
				ivFuelHeater.setVisibility(View.GONE);
				llHeaterToggle.setVisibility(View.GONE);
			}
		}

		@Override
		public void heatingMode(int heatingMode) {
			//当前模式
			if(heatingMode == 2){
				ivPtcHeater.setEnabled(true);
				ivFuelHeater.setEnabled(false);
				ivPtcHeater.setImageResource(R.drawable.img_ptc_bg_normal);
				ivFuelHeater.setImageResource(R.drawable.img_fuel_bg_selector);
				llHeaterToggle.setVisibility(View.VISIBLE);
				startAnimation();
			}else if(heatingMode == 1){
				ivPtcHeater.setEnabled(false);
				ivFuelHeater.setEnabled(true);
				ivPtcHeater.setImageResource(R.drawable.img_ptc_bg_selector);
				ivFuelHeater.setImageResource(R.drawable.img_fuel_bg_normal);
				llHeaterToggle.setVisibility(View.VISIBLE);
				//选择PTC加热模式后是否停止闪烁
				stopAnimation();
				//如果是燃油加热不足开始闪烁
                //startAnimation();
			}else{
				llHeaterToggle.setVisibility(View.GONE);
				stopAnimation();
			}
		}
	};

	private void startAnimation(){
		//选择PTC加热模式后是否停止闪烁||选择PTC加热模式后是否停止闪烁
		if(MCUUtil.mConditioningDecode.getFuelAlarm() == 1
				&& MCUUtil.mConditioningDecode.getHeatingMode() == 2
            ){
			ivFuelHeater.setImageResource(R.drawable.ic_heater_type_fuel_error_press);
			ivFuelHeater.clearAnimation();
			//ivFuelError.setAlpha(1f);
			ivFuelHeater.startAnimation(mAlphaAnim);
		}
	}
	private void stopAnimation(){
		if (mAlphaAnim != null) {
			mAlphaAnim.setAnimationListener(new Animation.AnimationListener() {
				@Override
				public void onAnimationStart(Animation animation) {
					AppLog.d(TAG, "mAlphaAnim onAnimationStart");
				}

				@Override
				public void onAnimationEnd(Animation animation) {
					AppLog.d(TAG, "mAlphaAnim onAnimationEnd");
					//ivFuelError.setAlpha(0f);
					ivFuelHeater.clearAnimation();
					ivFuelHeater.setAlpha(1.0f);
					if(MCUUtil.mConditioningDecode.getHeatingMode() == 2){
						ivFuelHeater.setImageResource(R.drawable.img_fuel_bg_selector);
					}else{
						ivFuelHeater.setImageResource(R.drawable.img_fuel_bg_normal);
					}
				}

				@Override
				public void onAnimationRepeat(Animation animation) {
					AppLog.d(TAG, "mAlphaAnim onAnimationRepeat");
				}
			});
		}
		mAlphaAnim.cancel();
//		if(MCUUtil.mConditioningDecode.getHeatingMode() == 2){
//			ivFuelHeater.setImageResource(R.drawable.img_fuel_bg_selector);
//		}else{
//			ivFuelHeater.setImageResource(R.drawable.img_fuel_bg_normal);
//		}
	}

	OnClickListener onClickListener = new OnClickListener() {
		@Override
		public void onClick(View v) {
			switch (v.getId()) {
				case R.id.iv_ptc_heater:
					ConditioningDecode.setPtcHeater();
					break;
				case R.id.iv_fuel_heater:
					ConditioningDecode.setFuelHeater();
					break;
			}
		}
	};

}
